import { http } from "@/utils/http";

/**
 * 统计数据接口
 */
export interface StatisticsInfo {
  total_loan_amount: number; // 1.放款总额
  self_loan_amount: number; // 2.自营放款
  assist_loan_amount: number; // 3.助贷
  month_loan_amount: number; // 4.本月放款
  month_self_loan_amount: number; // 5.本月自营放款
  month_assist_loan_amount: number; // 6.本月助贷
  today_loan_amount: number; // 7.今日放款统计
  total_pending_loan: number; // 8.合计待出款
  total_pending_repay: number; // 9.合计待回款
  total_settlement: number; // 10.结算总额
  total_brokers: number; // 11.经纪人总数
}

/**
 * 统计概览响应接口
 */
export interface StatisticsOverviewResponse {
  code: number;
  msg: string;
  error: number;
  success: boolean;
  data: StatisticsInfo;
}

/**
 * 获取统计概览数据
 */
export function getStatisticsOverview() {
  return http.request<StatisticsOverviewResponse>(
    "post",
    "/partner/statistics/overview",
    {}
  );
}

/**
 * 每日放款统计数据
 */
export interface DailyLoanStatistics {
  date: string; // 日期，格式：YYYY-MM-DD
  loan_amount: number; // 放款总额
}

/**
 * 每日统计数据响应接口
 */
export interface DailyStatisticsResponse {
  code: number;
  msg: string;
  error: number;
  success: boolean;
  data: {
    list: DailyLoanStatistics[]; // 每日放款列表
    total_amount: number; // 总放款金额
    target_amount: number; // 目标投放金额
    investment_rate: number; // 总体投放完成率
    total_charge: number; // 应收费总金额
    completed_charge: number; // 已收费金额
    charge_rate: number; // 总体收费完成率
  };
}

/**
 * 获取每日统计数据
 * @param params 请求参数，可包含日期范围等
 */
export function getDailyStatistics(params?: Record<string, any>) {
  return http.request<DailyStatisticsResponse>(
    "post",
    "/partner/statistics/daily",
    { params }
  );
}